package conson.tech.manage.facade.controller.coupons;


import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import conson.tech.core.constant.SecurityConstants;
import conson.tech.core.response.Response;
import conson.tech.manage.coupons.entity.dto.CouponsGrantDto;
import conson.tech.manage.coupons.entity.vo.CouponsGrantInformationVo;
import conson.tech.manage.coupons.entity.vo.CouponsGrantLogVo;
import conson.tech.manage.coupons.entity.vo.CouponsGrantVo;
import conson.tech.manage.coupons.service.CouponsGrantService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;

@Slf4j
@Api(value = "优惠券发放模块",tags = "优惠券发放模块")
@RestController
@RequestMapping((SecurityConstants.MANAGERAPI + "/coupons-grant"))
public class CouponsGrantController extends BaseController
{

        @Autowired
        private CouponsGrantService couponsGrantService;

        @ApiOperation(value = "查询优惠券发放列表")
        @ApiImplicitParam(name = "dto",value = "发放优惠券查询入参",required = true,dataType = "CouponsGrantDto")
        @PostMapping("/query-list/{pageSize}/{pageIndex}")
        public Response queryList(@ApiParam("每页条数") @PathVariable("pageSize") Integer pageSize,
                                              @ApiParam("页码") @PathVariable("pageIndex") Integer pageIndex,
                                              @ApiParam(value = "查询参数") @RequestBody(required = false) CouponsGrantDto dto){


            return Response.success(this.couponsGrantService.queryList(pageIndex,pageSize,dto));

        }

        @ApiOperation(value = "优惠券作废操作")
        @ApiImplicitParam(name = "couponsCode",value = "优惠券作废入参",required = true,dataType = "String")
        @GetMapping("/cancellation/{couponsCode}")
        public Response cancellationCoupons(HttpServletRequest request,@ApiParam("优惠券券码")@PathVariable("couponsCode") String couponsCode){

                //获取用户信息
                //Long userId = this.getCurrentUserId(request);
               // String userName = this.getCurrentUsername(request);
                 Long userId = 123456789L;
                String userName = "广电测试";

                return this.couponsGrantService.cancellationCoupons(couponsCode,userName,userId);
        }

        @ApiOperation(value = "全流程查看-优惠券")
        @ApiImplicitParam(name = "couponsCode",value = "优惠券券码",required = true,dataType = "String")
        @GetMapping("/cancellation/coupons/{couponsCode}")
        public Response cancellationCouponsInformation(@ApiParam("优惠券券码")@PathVariable("couponsCode") String couponsCode){

                return Response.success(this.couponsGrantService.cancellationCouponsInformation(couponsCode));
        }


        @ApiOperation(value = "全流程查看-日志")
        @ApiImplicitParam(name = "couponsCode",value = "优惠券券码",required = true,dataType = "String")
        @PostMapping("/cancellation/couponsLog/{pageSize}/{pageIndex}/{couponsCode}")
        public Response cancellationCouponsLog(@ApiParam("每页条数") @PathVariable("pageSize") Integer pageSize,
                                                              @ApiParam("页码") @PathVariable("pageIndex") Integer pageIndex,
                                                              @ApiParam("优惠券券码")@PathVariable("couponsCode") String couponsCode){



                return  Response.success(this.couponsGrantService.cancellationCouponsLog(pageIndex,pageSize,couponsCode));
        }

}
